package org.mics.sitemsg.controller;

import javax.annotation.Resource;
import javax.validation.Valid;

import org.mics.core.model.CurrentUser;
import org.mics.core.response.OneDataResponse;
import org.mics.core.response.PageDataResponse;
import org.mics.core.response.SimpleResponse;
import org.mics.lang.bean.BeanConvertUtil;
import org.mics.sitemsg.VO.SiteMsgVO;
import org.mics.sitemsg.entity.SiteMsgDO;
import org.mics.sitemsg.query.SiteMsgQuery;
import org.mics.sitemsg.service.SiteMsgService;
import org.mics.token.annotation.LoginUser;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;

/**
 * 站内信
 * @author mics
 * @date 2021-11-8
 * @version  1.0
 */
@RestController
@RequestMapping("/siteMsg")
@Tag(name = "站内信")
public class SiteMsgController {
	@Resource
	private SiteMsgService siteMsgService;
	
	
	@Operation(description = "未读消息数量")
	@RequestMapping(value = "/noReadNumber", method = RequestMethod.GET)
	public OneDataResponse<Long> noReadNumber(@LoginUser CurrentUser currentUser){
		Long noReadNumber= siteMsgService.noReadNumber(currentUser.getId());
		return new OneDataResponse<Long>(noReadNumber);
	}
	
	
	@Operation(description = "站内信分页列表")
	@RequestMapping(value = "/listByPage", method = RequestMethod.POST)
	public PageDataResponse<SiteMsgVO> listByPage(@RequestBody @Valid  SiteMsgQuery  siteMsgQuery,@LoginUser CurrentUser currentUser){
		PageDataResponse<SiteMsgVO> items = siteMsgService.listByPage(siteMsgQuery,currentUser.getId());
		return items;
	}
	
	
	@Operation(description = "站内信详情")
	@RequestMapping(value = "/info/{id}", method = RequestMethod.GET)
	public OneDataResponse<SiteMsgVO> info(@PathVariable("id")String id){
		SiteMsgDO siteMsgDO = siteMsgService.info(id);
		return new OneDataResponse<SiteMsgVO>(BeanConvertUtil.convert(siteMsgDO, SiteMsgVO.class));
	}
	
	
	@Operation(description = "删除站内信")
	@RequestMapping(value = "/remove/{id}",method = RequestMethod.DELETE)
	public SimpleResponse remove(@PathVariable("id")String id) {
		siteMsgService.remove(id);
		return new SimpleResponse();
	}
	
}
